package com.example.myapplication.ui

import androidx.room.ColumnInfo
import androidx.room.Ignore
import androidx.room.PrimaryKey
/**
 * 数据库表的抽象
 */
open class FileBean {

    companion object {
        const val STATE_NET_FLAG = "NET_"
        const val STATE_LOCAL_FLAG = "LOCAL_"
        const val STATE_DEFAULT_FLAG = "DEFAULT_"
    }

    @PrimaryKey(autoGenerate = true)
    @ColumnInfo(name = "id")
    var id: Int = 0

    @ColumnInfo(name = "uuid")
    var uuid: String

    @ColumnInfo(name = "name")
    var name: String? = null

    @ColumnInfo(name = "path")
    var path: String? = null

    @ColumnInfo(name = "type")
    var type: Int = 1

    @ColumnInfo(name = "enabled")
    var enabled: Boolean = true

    @ColumnInfo(name = "deleted")
    var deleted: Boolean = false

    @ColumnInfo(name = "createAt")
    var createAt: Long

    @ColumnInfo(name = "updateAt")
    var updateAt: Long

    @ColumnInfo(name = "length")
    var length: Long = -1

    @ColumnInfo(name = "state")
    var state: String = ""

    @Ignore
    var dbChange: Boolean = false

    constructor(uuid: String) {
        this.uuid = uuid
        this.createAt = System.currentTimeMillis()
        this.updateAt = createAt
    }

    constructor(bean : FileBean) {
        this. id = bean.id
        this. uuid= bean.uuid
        this. name= bean.name
        this. path= bean.path
        this. type= bean.type
        this. enabled= bean.enabled
        this. deleted= bean.deleted
        this. createAt= bean.createAt
        this. updateAt= bean.updateAt
        this. length= bean.length
        this. state= bean.state
    }

    fun set(bean: FileBean): FileBean {
        this.enabled = bean.enabled
        this.deleted = bean.deleted
        this.updateAt = bean.updateAt
        this.length = bean.length
        this.state = bean.state
        return this
    }

    override fun toString(): String {
        return "${hashCode()}  id=$id, uuid=$uuid  length=$length, state=$state  updateAt=$updateAt"
    }
}